﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.huigo.Framework.ServiceUtils;
using com.huigo.Framework.Passport;

namespace com.huigo.B2B.Web
{
    public partial class ProductDetail : BasePage
    {
        public long productId
        {
            get
            {
                string classId = Request.QueryString["id"];
                if (!string.IsNullOrEmpty(classId))
                {
                    try
                    {
                        return int.Parse(classId);
                    }
                    catch
                    {
                        return 0;
                    }
                }
                else
                {
                    return 0;
                }
            }
        }
        public string companyId = string.Empty;
        public string type = string.Empty;
        public string sellePrice = string.Empty;
        public string price = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            dataBind();
        }
        private void dataBind()
        {
            if (productId > 0)
            {
                List<RequestFuncParams> requestList = new List<RequestFuncParams>();
                requestList.Add(new RequestFuncParams("productId", productId.ToString()));
                BaseService service = new BaseService();
                ParserXml parserXml = service.RequestEntryService(Dict.ERequestFunc.GET_PRODUCT_INFO_BY_PRODUCT_ID, requestList);
                if (parserXml.RowsCount > 0)
                {
                    companyId = parserXml["CompanyId", 0];
                    type = parserXml["ProductTypeFid", 0];
                    sellePrice = parserXml["ProductSettlePrice", 0];
                    price = parserXml["ProductPrice", 0];
                    rptProduct.DataSource = parserXml.ModelList;
                    rptProduct.DataBind();
                    //选择控件显示
                    switch (Convert.ToInt16(parserXml["ProductTypeFid", 0]))
                    {
                        case (int)Dict.InsType.Air:
                            ctrl.AddAirPolicy airPolicyControl = (ctrl.AddAirPolicy)LoadControl("~/ctrl/AddAirPolicy.ascx");
                            airPolicyControl.ProductId = productId.ToString();
                            policyPlaceHolder.Controls.Add(airPolicyControl);
                            break;
                        case (int)Dict.InsType.Travel:
                            ctrl.AddTravelPolicy travelPolicyControl = (ctrl.AddTravelPolicy)LoadControl("~/ctrl/AddTravelPolicy.ascx");
                            travelPolicyControl.ProductId = productId.ToString();
                            policyPlaceHolder.Controls.Add(travelPolicyControl);
                            break;
                    }
                }
            }
        }
    }
}
